<?php
// 测试客户添加接口
$url = 'http://127.0.0.1:8000/api/crm/customer/add';
$token = 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJvYS5nb3VndWNtcy5jb20iLCJhdWQiOiJnb3VndW9hIiwiaWF0IjoxNzYzNjA2ODkzLCJleHAiOjE3NjM2OTMyOTMsInN1YiI6MSwiZGF0YSI6eyJ1c2VyaWQiOjF9fQ.uoy-81N0M1avew9a8YGJPYuB1fgbdcPmYaSdRhzT0SQ';

$data = [
    'name' => '测试客户',
    'phone' => '13800138001',
    'customer_type' => 2,
    'id_type' => 1,
    'id_number' => '110101199001011234',
    'customer_tags' => ['高价值', '推荐'],
    'level' => 1
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Authorization: ' . $token
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlError = curl_error($ch);
curl_close($ch);

    echo "HTTP状态码：" . $httpCode . "\n";
    echo "CURL错误：" . $curlError . "\n";
    
    // 如果有错误，获取更详细的错误信息
    if ($httpCode != 200 || !empty($curlError) || strpos($response, 'error') !== false) {
        echo "原始响应：" . $response . "\n";
    }

if ($response) {
    $jsonResponse = json_decode($response, true);
    if ($jsonResponse) {
        echo "解析后的响应：\n";
        print_r($jsonResponse);
    } else {
        echo "响应无法解析为JSON\n";
    }
}